package com.school.service;

import com.school.dao.TicketsDAO;
import com.school.entity.Tickets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TicketsService {
    @Autowired
    private TicketsDAO dao;

    @Override
    public String toString() {
        return "TicketsService{" +
                "dao=" + dao +
                '}';
    }

    public Tickets selectAll(String ticket_id) {
        Tickets tickets = dao.selectAll(ticket_id);
        return tickets;
    }

    public int insertOne(Tickets tickets) {
        int i = 0;
        if (tickets.getTicket_date() == null || tickets.getTicket_name() == null || tickets.getTicket_number() == null) {
            return 0;
        }
        try {
            i = dao.insertOne(tickets);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }

    public int updateOne(Tickets tickets) {
        int i = 0;
        try {
            i = dao.updateOne(tickets);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }

    public int deleteOne(String ticket_id) {
        int i = 0;
        try {
            i = dao.deleteOne(ticket_id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }

}
